package com.internetCafes.spms.common.AIRecognize.analyzer.impl;

import com.internetCafes.spms.common.AIRecognize.analyzer.Analyzer;
import com.internetCafes.spms.common.AIRecognize.handler.impl.*;
import com.internetCafes.spms.common.AIRecognize.recognizer.impl.Pic2WordAIRecognizer;
import com.internetCafes.spms.common.AIRecognize.QRCodeRecognizeUtils;
import com.internetCafes.spms.web.certificate.vo.AIRecognizeInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author LinYe
 * @date 2020/10/14
 */
@Component
public class WordAnalyzer implements Analyzer {

    @Autowired
    private CommonWordHandler commonWordHandler;

    @Autowired
    private QRCodeWordHandler qrCodeWordHandler;

    @Autowired
    private Pic2WordAIRecognizer pic2WordAIRecognizer;

    @Autowired
    private QualiWordHandler qualiWordHandler;

    @Autowired
    private ISOWordHandler isoWordHandler;

    @Autowired
    private HonorWordHandler honorWordHandler;

    @Override
    public AIRecognizeInfo analyze(String word, String filePath) {
        if (word.contains("</UploadResult>")||word.contains("<?xml")) {
            if (!word.startsWith("<")) {
                word = QRCodeRecognizeUtils.subSuffix(word);
                return qrCodeWordHandler.handle(word, filePath);
            }
                return pic2WordAIRecognizer.recognize(filePath);
        }
        if (word.contains("资质")){
            return qualiWordHandler.handle(word,filePath);
        }
        if (word.contains("认证证书")){
            return isoWordHandler.handle(word,filePath);
        }
        if (word.contains("AAA")){
            return honorWordHandler.handle(word,filePath);
        }
        return commonWordHandler.handle(word, filePath);
    }

    @Override
    public boolean match(String urlOrWord) {
        if (urlOrWord.startsWith("http:")) {
            return false;
        }
        return true;
    }
}
